package com.wq.jdk8;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author: wangqiang20995
 * @Date:2019/6/12
 * @Description:
 * @Resource:
 */
public class HashMapDemo {

    public static void main(String[] args){
        Map<String,String> map = new HashMap<>(2,0.75f);
        map.put("1","one");
        map.put("2","two");
        show(map);
        System.out.println(map.toString());

        List<String> list = new ArrayList<>(4);
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("5");
        list.add("6");
        System.out.println(list.size());


        String a = "三点半覅看三的方速冻";
        System.out.println(a.length() > 5 ? a.substring(0,5) : a);

        try{
            throw new RuntimeException("123");
        }catch (RuntimeException e){
            System.out.println(e.getMessage());
            throw new IllegalArgumentException(e);
        }catch (Exception e){
            System.out.println("error:" + e.getMessage());
        }

    }

    private static void show(Map<String,String> map){
        Map<String,String> temp = map;
        temp.put("3","three");
        System.out.println(temp);
    }

    private static String checkAndSubString(String old) {
        Pattern pattern = Pattern.compile("[\u4e00-\u9fa5]");
        Matcher matcher = pattern.matcher(old);
        List<String> list = new ArrayList<String>();
        while (matcher.find()) {
            list.add(matcher.group());
            if (list.size() >= 5) {
                break;
            }
        }

        StringBuilder builder = new StringBuilder();
        for (String code : list) {
            builder.append(code);
        }
        return builder.toString();
    }
}
